<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //可能出现两个或者以上一样的个数
        var str = 'nihaonihaoninihaohao';
        var arr = [];
        var length = str.length;
        for (var i = 0;i < length;i++){
            var char = str.charAt(i);
            if(arr[char]){
                arr[char]++;
            }else {
                arr[char] = 1;
            }
        }
        // console.log(arr);//输出完整对象，记录次数，遍历之后，找出次数最大

        var max = 0;
        for(var key in arr){
            if(max < arr[key]){
                max = arr[key];
            }
        }
        for(var key in arr){
            if(arr[key] === max){
                document.write('最多的字符是:' + key)
                document.write('出现的次数是:' + max)

            }
        }
    </script>
</body>
</html>